#include "tcp_conversitons.h"

TCPConversiations::TCPConversiations()
{
}

void TCPConversiations::add(struct tha &key, TCPSegment *val)
{
    map<tha, TCPConversiationElem>::iterator it = this->find(key);
    if(it == this->end())
    {
        TCPConversiationElem *temp = new TCPConversiationElem;
        if (val->rev)
        {
            temp->isn_ack = val->seq;
            temp->isn_seq = val->ack;
        }
        else
        {
            temp->isn_ack = val->ack;
            temp->isn_seq = val->seq;
        }
        if(val->payloadlen > 0)
        {
            temp->segments.push_back(*val);
        }
        this->insert(make_pair(key, *temp));
    }
    else
    {
        if (val->rev)
            val->seq -= it->second.isn_ack, val->ack -= it->second.isn_seq;
        else
            val->seq -= it->second.isn_seq, val->ack -= it->second.isn_ack;
        if(val->payloadlen > 0)
        {
            it->second.segments.push_back(*val);
        }
    }

}

void TCPConversiations::dump(FILE *fp)
{

}
